﻿using DocumentFormat.OpenXml.Math;
using ERP.Common.Results;
using ERP.Team.HumanResources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ERP.ERPSystem.HumanResources
{
    /// <summary>
    /// 人资系统-人才登记
    /// </summary>
    public class TalentregistrationService : ApplicationService,ITalentregistrationService
    {
        private readonly IRepository<TalentregistrationModel, int> _talentrepository;

        public TalentregistrationService(IRepository<TalentregistrationModel, int> talentrepository)
        {
            _talentrepository = talentrepository;
        }
        /// <summary>
        /// 人才登记列表
        /// </summary>
        /// <returns></returns>
        public async Task<APIPaging<TalentregistrationModel>> GetTalentregistrationModel(string? code, string? name, string? degree, string? status, int page = 1, int limit = 3 )
        {
            try
            {
                APIPaging<TalentregistrationModel> pageList = new APIPaging<TalentregistrationModel>();
                var TalentregistrationModel2 = await _talentrepository.GetQueryableAsync();// ((page - 1) * limit, limit, "CreatedAt DESC");
                TalentregistrationModel2=TalentregistrationModel2.WhereIf(!string.IsNullOrEmpty(code), m => m.EmployeeCode.Contains(code));
                TalentregistrationModel2 = TalentregistrationModel2.WhereIf(!string.IsNullOrEmpty(name), m => m.EmployeeName.Contains(name));
                TalentregistrationModel2 = TalentregistrationModel2.WhereIf(!string.IsNullOrEmpty(degree), m => m.Degree.Contains(degree));
                TalentregistrationModel2 = TalentregistrationModel2.WhereIf(!string.IsNullOrEmpty(status), m => m.Status.Contains(status));
                var TalentregistrationModel = TalentregistrationModel2.ToList();
                pageList.PageCount = TalentregistrationModel2.Count();
                pageList.ListDate = TalentregistrationModel.OrderByDescending(m=>m.Id).Skip((page-1)*limit).Take(limit).ToList();
                pageList.PageIndex = Convert.ToInt32(Math.Ceiling(pageList.PageCount * 1.0 / limit));
                return pageList;
            }
            catch (Exception)
            {

                throw;
            }
           
        }
    }
}
